using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FiltronASP.Helpers.CatalogueHelpers
{
    public class FilterRow
    {
        private const string YEARS_SEPARATOR = "->";
        private const string MONTHS_SEPARATOR = "/";
        private const int XXI_CENTURY_THRESHOLD = 20;
        private const int XXI_CENTURY_VALUE = 2000;
        private const int XX_CENTURY_VALUE = 1900;
        private const int DECEMBER = 12;

        public string Years { get; set; }

        public string Desc { get; set; }

        public int AirId { get; set; }

        public string AirDesc { get; set; }

        public int OilId { get; set; }

        public string OilDesc { get; set; }

        public int FuelId { get; set; }

        public string FuelDesc { get; set; }

        public int PaperId { get; set; }

        public string PaperDesc { get; set; }

        public int CarbonId { get; set; }

        public string CarbonDesc { get; set; }

        public int OtherId { get; set; }

        public string OtherDesc { get; set; }

        public bool ShowStyleInfo { get; set; }

        public int YearFrom 
        {
            get
            {
                if (String.IsNullOrEmpty(this.Years))
                {
                    return DateTime.Now.Year;
                }   //if
                try
                {
                    if (Years.IndexOf(YEARS_SEPARATOR) >= 0)
                    {
                        string RangeFrom = Years.Substring(0, Years.IndexOf(YEARS_SEPARATOR));
                        if (RangeFrom.IndexOf(MONTHS_SEPARATOR) >= 0)
                        {
                            int yearFrom = Int32.Parse(RangeFrom.Substring(RangeFrom.IndexOf(MONTHS_SEPARATOR) + 1));
                            if (yearFrom <= XXI_CENTURY_THRESHOLD)
                            {
                                return yearFrom + XXI_CENTURY_VALUE;
                            }   //if
                            return yearFrom + XX_CENTURY_VALUE;
                        }   //if
                    }   //if
                }   //try
                catch (Exception ex)
                {
                    Logger.MyLogger.Log(ex);
                }   //catch
                return DateTime.Now.Year;
            }
        }

        public int YearTo
        {
            get
            {
                if (String.IsNullOrEmpty(this.Years))
                {
                    return DateTime.Now.Year;
                }   //if
                try
                {
                    if (Years.IndexOf(YEARS_SEPARATOR) >= 0)
                    {
                        string RangeFrom = Years.Substring(Years.IndexOf(YEARS_SEPARATOR) + 2);
                        if (RangeFrom.IndexOf(MONTHS_SEPARATOR) >= 0)
                        {
                            int yearFrom = Int32.Parse(RangeFrom.Substring(RangeFrom.IndexOf(MONTHS_SEPARATOR) + 1));
                            if (yearFrom <= XXI_CENTURY_THRESHOLD)
                            {
                                return yearFrom + XXI_CENTURY_VALUE;
                            }   //if
                            return yearFrom + XX_CENTURY_VALUE;
                        }   //if
                    }   //if
                }   //try
                catch (Exception ex)
                {
                    Logger.MyLogger.Log(ex);
                }   //catch
                return DateTime.Now.Year;
            }
        }

        public int MonthFrom
        {
            get
            {
                if (String.IsNullOrEmpty(this.Years))
                {
                    return DECEMBER;
                }   //if
                try
                {
                    if (Years.IndexOf(YEARS_SEPARATOR) >= 0)
                    {
                        string RangeFrom = Years.Substring(0, Years.IndexOf(YEARS_SEPARATOR));
                        if (RangeFrom.IndexOf(MONTHS_SEPARATOR) >= 0)
                        {
                            return Int32.Parse(RangeFrom.Substring(0, RangeFrom.IndexOf(MONTHS_SEPARATOR)));
                        }   //if
                    }   //if
                }   //try
                catch (Exception ex)
                {
                    Logger.MyLogger.Log(ex);
                }   //catch
                return DECEMBER;
            }
        }

        public int MonthTo
        {
            get
            {
                if (String.IsNullOrEmpty(this.Years))
                {
                    return DECEMBER;
                }   //if
                try
                {
                    if (Years.IndexOf(YEARS_SEPARATOR) >= 0)
                    {
                        string RangeFrom = Years.Substring(Years.IndexOf(YEARS_SEPARATOR) + 2);
                        if (RangeFrom.IndexOf(MONTHS_SEPARATOR) >= 0)
                        {
                            return Int32.Parse(RangeFrom.Substring(0, RangeFrom.IndexOf(MONTHS_SEPARATOR)));
                        }   //if
                    }   //if
                }   //try
                catch (Exception ex)
                {
                    Logger.MyLogger.Log(ex);
                }   //catch
                return DECEMBER;
            }
        }

        

    }
}
